package utils;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;

import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @Author: DRevelation
 * @Date: 2021/1/26 19:38
 */
@Slf4j
public class CommonsThreadFactoryUtil {

    private static final ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(2,
                    new BasicThreadFactory.Builder().namingPattern("commons线程-%s").daemon(true).build());

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            exec.execute(() -> {
                log.info(DateUtil.now() + "===" + Thread.currentThread().getName());
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
        Thread.sleep(60 * 1000);
    }
}
